<?php include('pages/header.php') ?>

<script type="text/javascript" charset="utf-8">

function error(msg) {
	var d = $('#statusMessage');

	d.html(msg);
	d.show();
}

$(document).ready(function() {
	$('#statusMessage').hide();

	$('#submit').click(function() {
		var name = $('input[name=name]').val();
		if (name == '') {
			error("Name field can't be empty.");
			return false;
		}
		var midname = $('input[name=midname]').val();
		var lastname = $('input[name=lastname]').val();
		var faculty = $('input[name=faculty]').val();
		var gruppa = $('input[name=gruppa]').val();
		var room = $('input[name=room]').val();
		var roomcost = $('input[name=roomcost]').val();

		var args = {
			name: name,
			midname: midname,
			lastname: lastname,
			faculty: faculty,
			gruppa: gruppa,
			room: room,
			roomcost: roomcost,
<?php if ($editing) { ?>
			id: <?=$ppl['id']?>
<?php } ?>
		};

<!-- $.getJSON('tudent.php?cmd=add_do', args, function(r) {}); -->

		$.getJSON('student.php?cmd=add_do', args, function(r) {
			if (r.error_msg) {
				error(r.error_msg);
			} else {
				window.location = 'student.php?status_msg=' + escape(r.status_msg);
			}
		});


		return false;
	});
});
</script>

<label id="statusMessage">Hello</label><br/>
<table>
<tr>
    <td align="right">Фамилия:</td>
    <td><label>
      <input type="text" name="lastname" <?php if ($editing) echo ' value="'.$ppl['lastname'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Имя:</td>
    <td><label>
      <input type="text" name="name" <?php if ($editing) echo ' value="'.$ppl['name'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Отчество:</td>
    <td><label>
      <input type="text" name="midname" <?php if ($editing) echo ' value="'.$ppl['midname'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Факультет:</td>
    <td><label>
      <input type="text" name="faculty" <?php if ($editing) echo ' value="'.$ppl['faculty'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Группа:</td>
    <td><label>
      <input type="text" name="gruppa" <?php if ($editing) echo ' value="'.$ppl['gruppa'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Комната:</td>
    <td><label>
      <input type="text" name="room" <?php if ($editing) echo ' value="'.$ppl['room'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td align="right">Стоимость проживания:</td>
    <td><label>
      <input type="text" name="roomcost" <?php if ($editing) echo ' value="'.$ppl['roomcost'].'"' ?>/>
    </label></td>
</tr>
<tr>
    <td>
    <input type="submit" name="button" id="submit" value="Добавить"/>
    </td>
</tr>
</table>

<?php include('pages/footer.php'); ?>
